package com.mybatis.controller;

import com.mybatis.entity.TUser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

/**
 * 注解的handler
 * Created by 85243 on 2017/5/19.
 */
//标记一个控制器
@Controller
public class UserController3 {

//    @RequestMapping实现对QueryUsers方法和url进行映射
    @RequestMapping("/queryUsers")
    public ModelAndView queryUsers() throws Exception{


        List<TUser> userList = new ArrayList<>();

        TUser user1= new TUser();
        user1.setName("傻狗");
        user1.setId(1);
        userList.add(user1);
        TUser user2= new TUser();
        user2.setName("猪脑子");
        user2.setId(2);
        userList.add(user2);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("userList",userList);
        modelAndView.setViewName("/jsp/user/userList.jsp");
        return modelAndView;
    }
}
